<?
function get_headline($ID)
{
	$sql = "SELECT `summary` , `content` , `picture_ID` FROM `headlines` WHERE `ID` = $ID";
	$result = mysql_query($sql) or die("Cannot get headline: $ID") ;
	return $result;
}

function get_current_headline()
{
	$current_site_array = explode("/", $_SERVER['PHP_SELF']);
	$current_site = end($current_site_array);
	$sql = "SELECT DISTINCT `ID` FROM `headlines` WHERE `site` =  '$current_site'";
	$result = mysql_query($sql) or die ("Cannot get headline for $current_site");
	$headline_id = mysql_fetch_row($result);
	mysql_free_result($result);
	$headline = get_headline($headline_id[0]);
	$headline_details = mysql_fetch_assoc($headline);
	return $headline_details;
}
function get_current_body()
{
	$current_site_array = explode("/", $_SERVER['PHP_SELF']);
	$current_site = end($current_site_array);
	$sql = "SELECT `summary`,`body`,`main_image_id` FROM `bodies` WHERE `site` = '$current_site'";
	$result = mysql_query($sql) or die ("Cannot get body for $current_site");
	if (mysql_num_rows($result) != 0)
		$body_details = mysql_fetch_assoc($result);
	else
		$body_details = -1;
	return $body_details;
}

function get_all_current_events()
{
	$sql = 'SELECT `active_item_ID` FROM `backbone` WHERE `type_ID` = 2 ORDER BY (SELECT `date` FROM `events` WHERE `id` = `active_item_id`) DESC' ;
	$result = mysql_query($sql) or die("Cannot get current events");
	return $result;
}
function get_event($ID)
{
	$sql = "SELECT `date` , `summary` , `description` , `main_image_ID` FROM `events` WHERE `ID` = $ID";
	$result = mysql_query($sql) or die("Cannot get event: $ID") ;
	return $result;
}
function get_event_details($event_ID)
{
	$event = get_event($event_ID);
	$event_details = mysql_fetch_assoc($event);
	return $event_details;
}
function get_link($ID)
{
	$sql = "SELECT `title` , `link` , `audio_description` FROM `navigation_links` WHERE `ID` = $ID";
	$result = mysql_query($sql) or die("Cannot get link: $ID") ;
	return $result;
}

function get_footline($ID)
{
	$sql = "SELECT `content` FROM `footline` WHERE `ID` = $ID";
	$result = mysql_query($sql) or die("Cannot get footline: $ID") ;
	return $result;
}
function get_current_footline()
{
	$sql = 'SELECT `active_item_ID` FROM `backbone` WHERE `type_ID` = 5';
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	$footline = get_footline($row[0]);
	$footline_details = mysql_fetch_assoc($footline);
	return $footline_details;
}
function get_current_links()
{
	$sql = 'SELECT `active_item_ID` FROM `backbone` WHERE `type_ID` = 3 ORDER BY `order`';
	$result = mysql_query($sql) or die ("Cannot get links");
	return $result;
}

function get_link_details($link_row)
{
	$link = get_link($link_row[0]);
	$link_details = mysql_fetch_assoc($link);
	return $link_details;
}

function get_title($SITE)
{
	$sql = "SELECT `site_title` FROM `navigation_links` WHERE `link` = '$SITE'";
	$result = mysql_query($sql) or die ("Cannot get site title: $SITE");
	$title = mysql_fetch_assoc($result);
	if (mysql_num_rows($result) == 0)
		return " 0 ";
	else
	 	return $title['site_title'];
}
function get_all_active_events_ID()
{
	$sql = "SELECT `ID` FROM `events` WHERE `active` = 1 ORDER BY `date` DESC";
	$result = mysql_query($sql) or die ("Cannot get all active events");
	return $result;
}
function get_image_details($ID)
{
	$sql = "SELECT `title`, `image`, `image_thumbnail`,`audio_description`FROM `gallery` WHERE `ID` = $ID";
	$result = mysql_query($sql) or die ("Cannot get picture details" . $sql);
	$image_details = mysql_fetch_assoc($result);
	return $image_details;
}
function validate_login($login)
{
	$sql = "SELECT `name` FROM `passwords` WHERE `name` = '$login'";
	$result = mysql_query($sql) or die ("Cannot ask for login");
	if (mysql_num_rows($result) == 0)
		$login_details = 'any';
	else
		$login_details = mysql_result($result,0);
	return $login_details;
}
function get_password($login)
{
	$sql = "SELECT `password` FROM `passwords` WHERE `name` = '$login'";
	$result = mysql_query($sql) or die ("Cannot ask for password");
	if (mysql_num_rows($result)==0)
		$password_details = md5("ljsafksajdfiewjfi092984932jlkdsjflkdsj9i923923jkjkdsjf");
	else
		$password_details = mysql_result($result,0);
	return $password_details;
}
function get_event_month($event_date)
{
	if ($event_date == "" or $event_date == "0000-00-00")
		return "";
	else
	{
		list($year,$month,$day)=explode("-",$event_date);
		switch ($month){
	case 1:
		$month = "January";
		break;
	case 2:
		$month = "February";
		break;
	case 3:
		$month = "March";
		break;
	case 4:
		$month = "April";
		break;
	case 5:
		$month = "May";
		break;
	case 6:
		$month = "June";
		break;
	case 7:
		$month = "July";
		break;
	case 8:
		$month = "August";
		break;
	case 9:
		$month = "September";
		break;
	case 10:
		$month = "October";
		break;
	case 11:
		$month = "November";
		break;
	case 12:
		$month = "December";
		break;
	}
	return $month . " " . $year;
	}
}
function get_all_active_entries_ID()
{
	$sql = "SELECT `ID` FROM `blog` WHERE `active` = 1 ORDER BY `date` DESC";
	$result = mysql_query($sql) or die("Cannot get blog entries.");
	return $result;
}
function get_blog_entry($entry_ID)
{
	$sql = "SELECT `date` , `summary` , `content` ,`main_image_ID` FROM `blog` WHERE `ID` = $entry_ID";
	$result = mysql_query($sql) or die ("Cannot get blog entry with id" . $entry_ID . "<br/>" . $sql);
	return $result;
}
function get_blog_entry_details($entry_ID)
{
	$entry = get_blog_entry($entry_ID);
	$entry_details = mysql_fetch_assoc($entry);
	return $entry_details;
}
function get_all_gallery_event_ID()
{
	$sql = "SELECT `id` FROM `events` WHERE `main_image_ID` IS NOT NULL AND `active` = 1";
	$result = mysql_query($sql) or die ("Cannot get gallery events");
	return $result;
}
function get_gallery_event($event_ID)
{
	$sql = "SELECT * FROM `events` WHERE ID = $event_ID";
	$result = mysql_query($sql) or die ("Cannot get gallery event" . $sql);
	return $result;
}
function get_gallery_event_details($event_ID)
{
	$gallery_event = get_gallery_event($event_ID);
	$gallery_event_details = mysql_fetch_assoc($gallery_event);
	return $gallery_event_details;
}
function get_all_event_images_ID($event_ID)
{
	$sql="SELECT * FROM `gallery` WHERE `event_ID` = $event_ID and `active` = 1";
	$result = mysql_query($sql) or die("Cannot get images for event");
	return $result;
}
?>
